// miniprogram/pages/blindbox_box/blindbox_box.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
num:123
  },

  prizeShow: function () {
    var that = this;
    var phone = wx.getStorageSync('jlj1phone')
    var gonghao = wx.getStorageSync('gonghao')
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/choujiang/getcjusers?actid=42507&callback=?', //接收url
      data: {
        phone: phone,
        limits: 100
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        if (theJson.status === 2) {
          wx.request({ //发送请求
            url: 'https://zg99.offcn.com/index/choujiang/lottery?actid=42507&callback=?', //接收url
            data: {
              phone: phone,
              gonghao: gonghao
            }, //接收参数
            success(res) {
              var jsonStr = res.data;
              jsonStr = jsonStr.replace("(", "");
              jsonStr = jsonStr.replace(")", "");
              if (typeof jsonStr != 'object') {
                jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                var theJson = JSON.parse(jsonStr);
              }
              console.log(theJson)
              wx.setStorageSync('prizename2', theJson.prizename)
              // that.setData({
              //   jiang: true,
              //   isRunning: false
              // })
              wx.navigateTo({
                url: '../blindbox_index/blindbox_index',
              })

            }
          })

        } else if (theJson.status === 1) {
          wx.showModal({
            title: '您已经抽过奖了',
            content: '您获得了' + theJson.lists[0].prizename,
            showCancel: false, //去掉取消按钮
            success: function (res) {
              if (res.confirm) {
                that.setData({
                  isRunning: false
                })
              }

              wx.navigateTo({
                url: '../blindbox_res/blindbox_res',
              })
            }
          })
        } else {
          wx.showModal({
            title: '次数不足',
            content: '您已经进行过抽奖了！',
            showCancel: false, //去掉取消按钮
            success: function (res) {
              if (res.confirm) {
                that.setData({
                  isRunning: false
                })
              }
              wx.navigateTo({
                url: '../blindbox_res/blindbox_res',
              })
            }
          })
        }
      }
    })
  },
  change: function () {
    var that = this;
    var num = that.data.num;
    if (num == 123) {
      that.setData({
        num: 223
      })
    } else if (num == 223) {
      that.setData({
        num: 323
      })
    } else {
      that.setData({
        num: 123
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})